﻿#region Copyright & License
//
// Project: Quark Framework
// Project site: http://quark.codeplex.com
// See the copyright statement on the project site for more details.
//
// Licensed to the Apache Software Foundation (ASF) under one or more 
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership. 
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with 
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quark.Framework.Exceptions;

namespace Quark.Framework.Container
{
    /// <summary>
    /// 组件实例集合接口，一个组件实例集合仅持有一种类型组件的实例
    /// </summary>
    public interface IComponentInstanceCollection : 
        IInitializable, IContextualizable<IComponentInstanceCollectionContext>, IConfigurable, IParameterizable, IDisposable
    {
        /// <summary>
        /// 获取当前组件实例集合针对的组件实现类型
        /// </summary>
        Type ComponentImplementationType
        {
            get;
        }

        /// <summary>
        /// 获取当前实例集合包含的所有组件实例
        /// </summary>
        /// <remarks>
        /// 返回的枚举器完全脱离于内部组件实例集合，因此当前集合组件实例的变动不会影响到返回的枚举器实例。
        /// 每次返回的枚举器实例应是该获取瞬间的集合枚举，两次调用得到的枚举器实例是完全不同的
        /// </remarks>
        /// <threadsafety/>
        IEnumerator<IQuarkComponent> AllComponentInstances
        {
            get;
        }

        /// <summary>
        /// 创建一个新的组件实例并加入到当前组件实例集合中，
        /// 在返回该实例之前，新组件实例已经过初始化、置入上下文等初始化过程
        /// </summary>
        /// <returns>新的组件实例</returns>
        /// <exception cref="CreateComponentInstanceException">创建组件新实例异常，内部抛出的异常统一以<see cref="CreateComponentInstanceException"/>作为异常封装</exception>
        /// <threadsafety/>
        IQuarkComponent CreateNewComponentInstance();

        /// <summary>
        /// 删除当前集合中的所有组件实例
        /// </summary>
        /// <threadsafety/>
        void ClearComponentInstances();
    }

    /// <summary>
    /// 组件实例集合上下文接口
    /// </summary>
    public interface IComponentInstanceCollectionContext : IQuarkContext
    {
    }
}
